package com.chinasofti.service;

import com.chinasofti.dao.UserDaolmpl;
import com.chinasofti.domain.User;
import org.junit.Test;

import java.sql.Date;
import java.util.ArrayList;

public class UserService {
    UserDaolmpl dao = new UserDaolmpl();

    @Test
    public void testDelete(){
        int delete = dao.delete("22222222");
        System.out.println("delete = " + delete);
    }
    @Test
    public void testupdate(){
        User u = new User();
        u.setUid("33333333");
        u.setLoginname("alala");
        u.setPassword("1234561");
        u.setGender("女1");
        int insert = dao.update(u);
        System.out.println("insert = " + insert);
    }

    @Test
    public void testInset(){
        User u = new User();
        u.setUid("33333333");
        u.setLoginname("alalei");
        u.setUsername("阿拉蕾");
        u.setPassword("123456");
        u.setGender("女");
        u.setUcode("alalei001");
        u.setBirthday(new Date(2002,10,10));
        u.setDutydate(new Date(2022,12,12));
        int insert = dao.insert(u);
        System.out.println("insert = " + insert);
    }

    @Test
    public void testfindById(){
        User u = dao.findById("11111111");
        System.out.println("u = " + u);
    }

    @Test
    public void testfindAll(){
        ArrayList<User> all = dao.findAll();
        all.stream().forEach(System.out::println);
    }
    @Test
    public void testfindByLoginNameAndPassword(){
        User user = dao.findByLoginNameAndPassword("zhangsan", "123");
        if(user!=null){
            System.out.println("登录成功");
            System.out.println(user);
        }else{
            System.out.println("登录失败");
        }
    }

}